// --------------------------------------------------------------------------------------------
// Version: MPL 1.1/GPL 2.0/LGPL 2.1
// 
// The contents of this file are subject to the Mozilla Public License Version
// 1.1 (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
// http://www.mozilla.org/MPL/
// 
// Software distributed under the License is distributed on an "AS IS" basis,
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
// for the specific language governing rights and limitations under the
// License.
// 
// <remarks>
// Generated by IDLImporter from file nsIFocusManager.idl
// 
// You should use these interfaces when you access the COM objects defined in the mentioned
// IDL/IDH file.
// </remarks>
// --------------------------------------------------------------------------------------------
namespace Gecko
{
	using System;
	using System.Runtime.InteropServices;
	using System.Runtime.InteropServices.ComTypes;
	using System.Runtime.CompilerServices;
	
	
	/// <summary>
    /// The focus manager deals with all focus related behaviour. Only one element
    /// in the entire application may have the focus at a time; this element
    /// receives any keyboard events. While there is only one application-wide
    /// focused element, each nsIDOMWindow maintains a reference to the element
    /// that would be focused if the window was active.
    ///
    /// If the window's reference is to a frame element (iframe, browser,
    /// editor), then the child window contains the element that is currently
    /// focused. If the window's reference is to a root element, then the root is
    /// focused. If a window's reference is null, then no element is focused, yet
    /// the window is still focused.
    ///
    /// The blur event is fired on an element when it loses the application focus.
    /// After this blur event, if the focus is moving away from a document, two
    /// additional blur events are fired on the old document and window containing
    /// the focus respectively.
    ///
    /// When a new document is focused, two focus events are fired on the new
    /// document and window respectively. Then the focus event is fired on an
    /// element when it gains the application focus.
    ///
    /// A special case is that the root element may be focused, yet does not
    /// receive the element focus and blur events. Instead a focus outline may be
    /// drawn around the document.
    ///
    /// Blur and focus events do not bubble as per the W3C DOM Events spec.
    /// </summary>
	[ComImport()]
	[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
	[Guid("2487F9CA-D05F-4BD1-8F43-5964E746C482")]
	public interface nsIFocusManager
	{
		
		/// <summary>
        /// The most active (frontmost) window, or null if no window that is part of
        /// the application is active. Setting the activeWindow raises it, and
        /// focuses the current child window's current element, if any. Setting this
        /// to null or to a non-top-level window throws an NS_ERROR_INVALID_ARG
        /// exception.
        /// </summary>
		[return: MarshalAs(UnmanagedType.Interface)]
		[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
		nsIDOMWindow GetActiveWindowAttribute();
		
		/// <summary>
        /// The most active (frontmost) window, or null if no window that is part of
        /// the application is active. Setting the activeWindow raises it, and
        /// focuses the current child window's current element, if any. Setting this
        /// to null or to a non-top-level window throws an NS_ERROR_INVALID_ARG
        /// exception.
        /// </summary>
		[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
		void SetActiveWindowAttribute([MarshalAs(UnmanagedType.Interface)] nsIDOMWindow aActiveWindow);
		
		/// <summary>
        /// The child window within the activeWindow that is focused. This will
        /// always be activeWindow, a child window of activeWindow or null if no
        /// child window is focused. Setting the focusedWindow changes the focused
        /// window and raises the toplevel window it is in. If the current focus
        /// within the new focusedWindow is a frame element, then the focusedWindow
        /// will actually be set to the child window and the current element within
        /// that set as the focused element. This process repeats downwards until a
        /// non-frame element is found.
        /// </summary>
		[return: MarshalAs(UnmanagedType.Interface)]
		[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
		nsIDOMWindow GetFocusedWindowAttribute();
		
		/// <summary>
        /// The child window within the activeWindow that is focused. This will
        /// always be activeWindow, a child window of activeWindow or null if no
        /// child window is focused. Setting the focusedWindow changes the focused
        /// window and raises the toplevel window it is in. If the current focus
        /// within the new focusedWindow is a frame element, then the focusedWindow
        /// will actually be set to the child window and the current element within
        /// that set as the focused element. This process repeats downwards until a
        /// non-frame element is found.
        /// </summary>
		[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
		void SetFocusedWindowAttribute([MarshalAs(UnmanagedType.Interface)] nsIDOMWindow aFocusedWindow);
		
		/// <summary>
        /// The element that is currently focused. This will always be an element
        /// within the document loaded in focusedWindow or null if no element in that
        /// document is focused.
        /// </summary>
		[return: MarshalAs(UnmanagedType.Interface)]
		[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
		nsIDOMElement GetFocusedElementAttribute();
		
		/// <summary>
        /// Returns the method that was used to focus the element in window. This
        /// will either be 0, FLAG_BYMOUSE or FLAG_BYKEY. If window is null, then
        /// the current focusedWindow will be used by default. This has the result
        /// of retrieving the method that was used to focus the currently focused
        /// element.
        /// </summary>
		[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
		uint GetLastFocusMethod([MarshalAs(UnmanagedType.Interface)] nsIDOMWindow window);
		
		/// <summary>
        /// Changes the focused element reference within the window containing
        /// aElement to aElement.
        /// </summary>
		[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
		void SetFocus([MarshalAs(UnmanagedType.Interface)] nsIDOMElement aElement, uint aFlags);
		
		/// <summary>
        /// Move the focus to another element. If aStartElement is specified, then
        /// movement is done relative to aStartElement. If aStartElement is null,
        /// then movement is done relative to the currently focused element. If no
        /// element is focused, focus the first focusable element within the
        /// document (or the last focusable element if aType is MOVEFOCUS_END). This
        /// method is equivalent to setting the focusedElement to the new element.
        ///
        /// Specifying aStartElement and using MOVEFOCUS_LAST is not currently
        /// implemented.
        ///
        /// If no element is found, and aType is either MOVEFOCUS_ROOT or
        /// MOVEFOCUS_CARET, then the focus is cleared. If aType is any other value,
        /// the focus is not changed.
        ///
        /// Returns the element that was focused. The return value may be null if focus
        /// was moved into a child process.
        /// </summary>
		[return: MarshalAs(UnmanagedType.Interface)]
		[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
		nsIDOMElement MoveFocus([MarshalAs(UnmanagedType.Interface)] nsIDOMWindow aWindow, [MarshalAs(UnmanagedType.Interface)] nsIDOMElement aStartElement, uint aType, uint aFlags);
		
		/// <summary>
        /// Clears the focused element within aWindow. If the current focusedWindow
        /// is a descendant of aWindow, sets the current focusedWindow to aWindow.
        ///
        /// @throws NS_ERROR_INVALID_ARG if aWindow is null
        /// </summary>
		[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
		void ClearFocus([MarshalAs(UnmanagedType.Interface)] nsIDOMWindow aWindow);
		
		/// <summary>
        /// Returns the currently focused element within aWindow. If aWindow is equal
        /// to the current value of focusedWindow, then the returned element will be
        /// the application-wide focused element (the value of focusedElement). The
        /// return value will be null if no element is focused.
        ///
        /// If aDeep is true, then child frames are traversed and the return value
        /// may be the element within a child descendant window that is focused. If
        /// aDeep if false, then the return value will be the frame element if the
        /// focus is in a child frame.
        ///
        /// aFocusedWindow will be set to the currently focused descendant window of
        /// aWindow, or to aWindow if aDeep is false. This will be set even if no
        /// element is focused.
        ///
        /// @throws NS_ERROR_INVALID_ARG if aWindow is null
        /// </summary>
		[return: MarshalAs(UnmanagedType.Interface)]
		[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
		nsIDOMElement GetFocusedElementForWindow([MarshalAs(UnmanagedType.Interface)] nsIDOMWindow aWindow, [MarshalAs(UnmanagedType.U1)] bool aDeep, [MarshalAs(UnmanagedType.Interface)] ref nsIDOMWindow aFocusedWindow);
		
		/// <summary>
        /// Moves the selection caret within aWindow to the current focus.
        /// </summary>
		[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
		void MoveCaretToFocus([MarshalAs(UnmanagedType.Interface)] nsIDOMWindow aWindow);
		
		/// <summary>
        /// Check if given element is focusable.
        /// </summary>
		[return: MarshalAs(UnmanagedType.U1)]
		[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
		bool ElementIsFocusable([MarshalAs(UnmanagedType.Interface)] nsIDOMElement aElement, uint aFlags);
		
		/// <summary>
        /// Called when a window has been raised.
        /// </summary>
		[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
		void WindowRaised([MarshalAs(UnmanagedType.Interface)] nsIDOMWindow aWindow);
		
		/// <summary>
        /// Called when a window has been lowered.
        /// </summary>
		[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
		void WindowLowered([MarshalAs(UnmanagedType.Interface)] nsIDOMWindow aWindow);
		
		/// <summary>
        /// Called when a new document in a window is shown.
        ///
        /// If aNeedsFocus is true, then focus events are expected to be fired on the
        /// window if this window is in the focused window chain.
        /// </summary>
		[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
		void WindowShown([MarshalAs(UnmanagedType.Interface)] nsIDOMWindow aWindow, [MarshalAs(UnmanagedType.U1)] bool aNeedsFocus);
		
		/// <summary>
        /// Called when a document in a window has been hidden or otherwise can no
        /// longer accept focus.
        /// </summary>
		[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
		void WindowHidden([MarshalAs(UnmanagedType.Interface)] nsIDOMWindow aWindow);
		
		/// <summary>
        /// Fire any events that have been delayed due to synchronized actions.
        /// </summary>
		[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
		void FireDelayedEvents(System.IntPtr aDocument);
		
		/// <summary>
        /// Indicate that a plugin wishes to take the focus. This is similar to a
        /// normal focus except that the widget focus is not changed. Updating the
        /// widget focus state is the responsibility of the caller.
        /// </summary>
		[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
		void FocusPlugin(System.IntPtr aPlugin);
		
		/// <summary>
        /// Used in a child process to indicate that the parent window is now
        /// active or deactive.
        /// </summary>
		[MethodImpl(MethodImplOptions.InternalCall, MethodCodeType=MethodCodeType.Runtime)]
		void ParentActivated([MarshalAs(UnmanagedType.Interface)] nsIDOMWindow aWindow, [MarshalAs(UnmanagedType.U1)] bool active);
	}
	
	/// <summary>nsIFocusManagerConsts </summary>
	public class nsIFocusManagerConsts
	{
		
		// <summary>
        // Raise the window when switching focus
        // </summary>
		public const ulong FLAG_RAISE = 1;
		
		// <summary>
        // Do not scroll the element to focus into view
        // </summary>
		public const ulong FLAG_NOSCROLL = 2;
		
		// <summary>
        // If attempting to change focus in a window that is not focused, do not
        // switch focus to that window. Instead, just update the focus within that
        // window and leave the application focus as is. This flag will have no
        // effect if a child window is focused and an attempt is made to adjust the
        // focus in an ancestor, as the frame must be switched in this case.
        // </summary>
		public const ulong FLAG_NOSWITCHFRAME = 4;
		
		// <summary>
        // This flag is only used when passed to moveFocus. If set, focus is never
        // moved to the parent frame of the starting element's document, instead
        // iterating around to the beginning of that document again. Child frames
        // are navigated as normal.
        // </summary>
		public const ulong FLAG_NOPARENTFRAME = 8;
		
		// <summary>
        // Focus is changing due to a mouse operation, for instance the mouse was
        // clicked on an element.
        // </summary>
		public const ulong FLAG_BYMOUSE = 0x1000;
		
		// <summary>
        // Focus is changing due to a key operation, for instance pressing the tab
        // key. This flag would normally be passed when MOVEFOCUS_FORWARD or
        // MOVEFOCUS_BACKWARD is used.
        // </summary>
		public const ulong FLAG_BYKEY = 0x2000;
		
		// <summary>
        // Focus is changing due to a call to MoveFocus. This flag will be implied
        // when MoveFocus is called except when one of the other mechanisms (mouse
        // or key) is specified, or when the type is MOVEFOCUS_ROOT or
        // MOVEFOCUS_CARET.
        // </summary>
		public const ulong FLAG_BYMOVEFOCUS = 0x4000;
		
		// <summary>
        // Always show the focus ring or other indicator of focus, regardless of
        // other state.
        // </summary>
		public const ulong FLAG_SHOWRING = 0x100000;
		
		// <summary>
        // Focus is changing due to a touch operation that generated a mouse event.
        // Normally used in conjunction with FLAG_BYMOUSE.
        // </summary>
		public const ulong FLAG_BYTOUCH = 0x200000;
		
		// <summary>
        //move focus forward one element, used when pressing TAB </summary>
		public const ulong MOVEFOCUS_FORWARD = 1;
		
		// <summary>
        //move focus backward one element, used when pressing Shift+TAB </summary>
		public const ulong MOVEFOCUS_BACKWARD = 2;
		
		// <summary>
        //move focus forward to the next frame document, used when pressing F6 </summary>
		public const ulong MOVEFOCUS_FORWARDDOC = 3;
		
		// <summary>
        //move focus forward to the previous frame document, used when pressing Shift+F6 </summary>
		public const ulong MOVEFOCUS_BACKWARDDOC = 4;
		
		// <summary>
        //move focus to the first focusable element </summary>
		public const ulong MOVEFOCUS_FIRST = 5;
		
		// <summary>
        //move focus to the last focusable element </summary>
		public const ulong MOVEFOCUS_LAST = 6;
		
		// <summary>
        //move focus to the root element in the document </summary>
		public const ulong MOVEFOCUS_ROOT = 7;
		
		// <summary>
        //move focus to a link at the position of the caret. This is a special value used to
        // focus links as the caret moves over them in caret browsing mode.
        // </summary>
		public const ulong MOVEFOCUS_CARET = 8;
		
		// <summary>
        //move focus to the first focusable document </summary>
		public const ulong MOVEFOCUS_FIRSTDOC = 9;
		
		// <summary>
        //move focus to the last focusable document </summary>
		public const ulong MOVEFOCUS_LASTDOC = 10;
	}
}
